<?php

class Article extends MY_Controller {

	function Article()
	{
		parent::MY_Controller();
		$this->load->model('Article_model');
		
	}
	
	function index()
	{	
		// Set meta
		$title = $this->data['site']['site_title'];
		$data['web_title'] = $title;
		$data['meta_title'] = $title;
		$data['meta_description'] = purify($this->data['site']['site_description']);
		$data['meta_keyword'] = $this->data['site']['site_keyword'];
		
		// Paging Setting URL segment
		$segment =1;
		
		if($this->uri->segment($segment) == "pages" && $this->uri->segment($segment+1))
		{
			$page = $this->uri->segment($segment+1);
			$replace = str_replace('_html','',$this->uri->segment(3));
			$data['active_segment'] = '/'.$replace;	

		}
		else
		{
			$page = 1;
			$replace = str_replace('_html','',$this->uri->segment(1));
			$data['active_segment'] = '/'.$replace;	

		}
		
		$paging_url = "pages/";
		
		// Default Paging Setting
		$show = 7;
		$offset = 5;
		$start = (($page-1) * $show);
		$notArray = array(1,2);
		$total = $this->Article_model->get_rows('article.id')->num_rows();
		
		// Get Artikel LIST
		$data['article'] = $this->Article_model->get_rows('article.id as id_art, title,description,content,image,article.created_date,user.id as id_usr,name','','',$show,$start)->result_array();
		
		// Get Paging		
		$data['paging'] = paging($page,$show,$total,$offset);		
		$data['paging_link'] = $this->_set_paging_link($data['paging']);	
		$data['paging_url'] = $paging_url;
		
		
		// Send and Load page
		$data['page'] = 'article_view';
		$this->load->vars($data);
		$this->load->view('template_view');	
	}
	
	function detail($id)
	{			
		// Set meta
		$title = $this->data['site']['site_title'];
		$data['web_title'] = $title;
		$data['meta_title'] = $title;
		$data['meta_description'] = purify($this->data['site']['site_description']);
		$data['meta_keyword'] = $this->data['site']['site_keyword'];
		
		// Get article
		$data['detail_article'] = $this->Article_model->get_row('*','id',$id)->row_array();
		
				
		
		// Send and Load page
		$data['page'] = 'articledetail_view';
		$this->load->vars($data);
		$this->load->view('template_view');		
	}
}	

/* End of file home.php */
/* Location: ./application/controllers/home.php */
?>